// import JSEncrypt from 'jsencrypt/bin/jsencrypt'
// // 公钥,用于加密前端数据,只可以用后端私钥解密
// const PUBLIC_KEY = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHYPeCWqE+GQjQaGYA+OwOpVSf
// Ukq+rNHbEQq/uE2kYMOfkWx/Grb4UNtp1VF7j0v1WplPP0cROcH2iKNdeTIx91p7
// a6oj3JZAA36zn4UzxDwvszgB4CM0kzEvLZeSn7Xi6IL+XOs6xgLdHA9RzXevc1vC
// 8cuE9p4454/4uFxBSQIDAQAB`
//
// //和后端的公钥对应,只用于后端数据解密
// const PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMdg94JaoT4ZCNBo\n" +
//   "ZgD47A6lVJ9SSr6s0dsRCr+4TaRgw5+RbH8atvhQ22nVUXuPS/VamU8/RxE5wfaI\n" +
//   "o115MjH3WntrqiPclkADfrOfhTPEPC+zOAHgIzSTMS8tl5KfteLogv5c6zrGAt0c\n" +
//   "D1HNd69zW8Lxy4T2njjnj/i4XEFJAgMBAAECgYAUljeYVyFVFyKo2k7GBO3i6UFe\n" +
//   "nhGntJKKqyzP9QjXU0J/xHVOfoSsCTVOrT8Xogk20V8JJsCAz9TuTteHfE8pWOoA\n" +
//   "Bz2gqyEltJLpCIydy1O8bkKlV2H+3vYl1jhgFwBo3wCaDoq1Ffv545CY+1CUT1vs\n" +
//   "9HBmq+kp0vRcQ5nb8QJBAO02t+/GPdon8QZtGD28iRzKfBp1/TJiPrmuGb7qHqIz\n" +
//   "IzzotcTJfCUhE0n6RrXuB7hzMnAp3kFf3SCfXG67Tl0CQQDXKy47oQRvPSKMT2Y2\n" +
//   "Z8Ty0hC8ZDadNYHJbu14II9dizpDjO1XX+obhs95ikKEZKIYfhjfP7QWlo1BUKd8\n" +
//   "qFfdAkEA5jpgZWgbqftwE9OYXnr4/KeNscToXJk71c0jEcd6ueQ2BCy8FmWThxnF\n" +
//   "9dvh+zst5RhxUKliHEMlhD8HYDWMxQJBAMZYgsTq+EiGxZsr8iAC5lWkeVMA2itv\n" +
//   "UJXcUMGk2iO0HWB5v6wEuazoR8dVQV4D2jzTuJ/LfHo6DDqCW/KYyG0CQG6f7jpZ\n" +
//   "PE3iou/NKDIIZhWA0dBuRddjREBajTBkiBTSTDH/TBLYXmhq8rS8NrVyPtd4icIB\n" +
//   "qfszJV5Nesgt0Zo=";
//
// /**
//  * 加密
//  * @param data
//  * @returns {PromiseLike<ArrayBuffer>}
//  */
// export function encrypt(data) {
//   // 使用公钥加密
//   const encrypt = new JSEncrypt()
//   encrypt.setPublicKey(PUBLIC_KEY)
//   let result = encrypt.encrypt(data)
//   return result
// }
//
// /**
//  * 解密
//  * @param data
//  * @returns {string}
//  */
// export function decrypt(data) {
//   let d = JSON.stringify(data);
//   d = d.replace('"', '');
//   d = d.replace('"', '');
//   //使用私钥解密
//   const decrypt = new JSEncrypt()
//   decrypt.setPrivateKey(PRIVATE_KEY)
//   let sub = d.split('=');
//   let result = '';
//   for (let i of sub) {
//     if (i === '') {
//       break;
//     }
//     result = result + decrypt.decrypt(i)
//   }
//   return result
// }
import CryptoJS from "crypto-js";

const keyStr = 'Ha3Zie6ZufJnECBz';

export function encrypt(word) {
  let key = CryptoJS.enc.Utf8.parse(keyStr);
  let srcs = CryptoJS.enc.Utf8.parse(word);
  let encrypted = CryptoJS.AES.encrypt(srcs, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

// 解密
export function decrypt(word) {
  var key = CryptoJS.enc.Utf8.parse(keyStr);
  var decrypt = CryptoJS.AES.decrypt(word, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
